package com.neusoft.action;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.neusoft.bean.AdminInfoBean;
import com.neusoft.bean.AdminInfoBeanQuery;
import com.neusoft.util.MyUtil;
import com.neusoft.service.AdminInfoService;

/**
 * 控制层的响应类：通过注解@Controller说明这是一个控制层的类
 * 注意：servlet框架是类级别的响应，使用类的注解@webServlet进行路径映射
 * springmvc、struts2框架是方法级别的响应，使用方法的注解@RequestMapping进行路径映射
 * 
 * @author Administrator
 *
 */
@Controller
public class AdminInfoAction {

	/**
	 * 登录
	 * 
	 * @param adminB
	 *            实体bean
	 * @return 转发网页jsp名
	 */
	@RequestMapping("/doAdminLogin")
	public String doAdminLogin(AdminInfoBean adminB) {
		String strV = "../../login";
		System.out.println("登录用户名:" + adminB.getAdminname() + "密码:" + adminB.getAdminpsw());

		List<AdminInfoBean> adminLst = MyUtil.getInstance(AdminInfoService.class).doAdminLogined(adminB);
		if (adminLst != null && adminLst.size() > 0) {
			strV = "main";
		}
		return strV;
	}

	/**
	 * 添加用户
	 * 
	 * @param adminB
	 * @param request
	 * @return
	 */
	@RequestMapping("/addAdminInfo")
	public String addAdminInfo(AdminInfoBean adminB, HttpServletRequest request) {

		MyUtil.getInstance(AdminInfoService.class).doAddAdminInfo(adminB);

		List<AdminInfoBean> aiblst = MyUtil.getInstance(AdminInfoService.class).getAllAdminInfo();
		request.getSession().setAttribute("aiblst", aiblst);

		return "admininfo/addAdminInfo";
	}

	/**
	 * 
	 * 添加@ResponseBody注解：该方法会进行ajax响应，该方法只需要返回需要转换为josn的数据结构类型即可；
	 * 
	 * springmvc框架会使用jackson插件将返回的数据结构转换为json字符串响应给客户端
	 * 
	 * @param adminB
	 * 
	 * @return
	 * 
	 */
	@ResponseBody
	@RequestMapping("/AjaxQueryAdmin")
	public List<AdminInfoBean> AjaxQueryAdmin(AdminInfoBeanQuery adminB) {
		List<AdminInfoBean> aiblst = MyUtil.getInstance(AdminInfoService.class).getAdminInfo(adminB);
		return aiblst;

	}
}
